<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工作台账</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="./../js/index.js"></script>
    <style>
         body {
            font-size: 1rem;
        } 

        /* td {
            text-align: center;
        } */
    </style>
</head>

<body>
    <div id="app" class="container-fluid">
        <nav class="navbar bg-body-tertiary">
            <form class="container-fluid justify-content-start">
                <button class="btn btn-outline-success me-2 " type="button" onclick="to_demo()">台账</button>
                <button class="btn btn-outline-success me-2" type="button" onclick="to_demo1()">掉线</button>
                <button class="btn btn-outline-success me-2 active" type="button">测试</button>
            </form>
        </nav>



        <br>
        <div class="container-fluid">
            <table class="table table-striped" id="myTable">
                <thead>
                    <!-- <tr>
                        <th>时间</th>
                        <th>车牌</th>
                        <th>速度</th>
                        <th>位置</th>
                    </tr> -->
                </thead>
                <tbody id="copyBtn">
                    <tr v-for="(item, index) in this.carCodeArray" :key="index">
                        <td class="col-sm-1">{{item.str1}}</td>
                        <td class="col-sm-2">{{item.str2}}</td>
                        <td class="col-sm-1">{{item.str3}}</td>
                        <td class="col-sm-8">{{item.str4}}</td>
                    </tr>

                </tbody>
            </table>

            <br>
            <br>
            <br>
            <!-- <div class="form-group"> -->
            <textarea class="form-control" rows="6" @keyup.enter="handleEnter" v-model="inputInfo"
                placeholder="新增台账"></textarea>
            
            <textarea class="form-control" rows="12" placeholder="暂存车牌"></textarea>

            <button style="float: right;" class="btn btn-outline-success me-2" type="button" onclick="location.reload();">清空数据</button>

        </div>

    </div>
    <script src="./../js/vue.js"></script>
    <script>




        const app = new Vue({
            el: '#app',
            data: {
                msg: '您好，赵永利',
                carCodeArray: [],
                inputStr: '',
                inputInfo: '',
                copyTextarea: '',
                carInfo: {
                    str1: '',
                    str2: '',
                    str3: '',
                    str4: ''
                }

            },
			created() {
                // 设置定时器定时更新
                this.timer = setInterval(() => {
                   
                    this.addNodata()
                    this.getValue()
                }, 500);
            },

            beforeDestroy() {
                // 清除定时器以避免内存泄漏
                clearInterval(this.timer);
            },
            methods: {

                handleEnter() {
                    this.addNodata()
                    this.getValue()
                },


                addNodata() {
				
					if (this.inputInfo.trim().indexOf('定位位置') !== -1) {
                        return
                    }
					if(this.inputInfo.trim()==''){
						
						return
					}
					var noDatainfo = this.inputInfo.trim()
                    var strArray = noDatainfo.split(/\r\n|\n/)
					if(strArray.length !=9 && strArray.length !=10){
						console.log("数组长度-------------"+strArray.length)
						return
					}

                    
					
					if (strArray[1].trim().indexOf('粤') == -1) {
                        return
                    }
					
					if (strArray[2].trim().indexOf('色') == -1) {
                        return
                    }

                    if(strArray.length==9 && strArray[6].trim().indexOf('km/h') == -1){
                        return
                    }

                    if(strArray.length==10 && strArray[7].trim().indexOf('km/h') == -1){
                        return
                    }
					
					
					


                    str1 = strArray[1]
                    if(strArray.length==9){
                        str4 = strArray[7]
                    }
                    if(strArray.length==10){
                        str4 = strArray[8]
                    }
                    //str4 = strArray[7]
                    console.log(str1)
                    console.log(str4)
                    carInfo = new Object();
                    carInfo.str1 = '设置时间'
                    carInfo.str2 = str1.trim()
                    carInfo.str3 = 0
                    carInfo.str4 = str4.trim()
                    this.carCodeArray.push(carInfo)
                    this.inputInfo = ''

                },
				// 设置有轨迹数据
                getValue() {
					if(this.inputInfo==''){
						return 
					}
					var info = this.inputInfo.trim()
					
					var strArray = info.split(/\r\n|\n/)
					
					if(strArray.length !=9){
						
						return
					}
					//获取车牌		
					if (strArray[0].indexOf('粤') !== -1) {

                    } else {
                        console.log("不包含车牌-------------")
                        return
                    }					
					var str2 = strArray[0].trim()
					
                    console.log("获取车牌：" + str2)
					
					//获取定位时间
					if (strArray[2].indexOf('定位时间') !== -1) {

                    } else {
                        console.log("不包含定位时间-------------")
                        return
                    }
					var str1 = strArray[2].substring(17).trim()
					
                    console.log("获取定位时间：" + str1)
					//获取定位位置
					if (strArray[8].indexOf('定位位置') !== -1) {

                    } else {
                        console.log("不包含定位位置-------------")
                        return
                    }
                    var str4 = strArray[8].substring(6).trim()
					
                    console.log("获取定位位置：" + str4)
					//获取行驶速度	
					if (strArray[5].indexOf('行驶速度') !== -1) {

                    } else {
                        console.log("不包行驶速度-------------")
                        return
                    }
                    var strPosition7 = strArray[5].indexOf('km/h')
                    var str3 = strArray[5].substring(6,strPosition7).trim()
					
                    console.log("获取行驶速度：" + str3)

                    carInfo = new Object();
					carInfo.str1 = str1
					carInfo.str2 = str2
					carInfo.str3 = Math.round(str3)
					carInfo.str4 = str4
					this.carCodeArray.push(carInfo)
                    this.inputInfo = ''

                }
            }




        })



    </script>
    <script src="../js/bootstrap.bundle.min.js"></script>
</body>

</html>